<template>
    <el-container>
        <el-header>
            <h4>安心保险</h4>
            <div id="header-right">
                <el-dropdown v-if="code == 1">
                    <span class="el-dropdown-link">
                        管理员<i class="el-icon-arrow-down el-icon--right"></i>
                    </span>

                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>个人信息</el-dropdown-item>
                        <el-dropdown-item>切换账号</el-dropdown-item>
                        <el-dropdown-item>
                            <span @click="outAdmin">退出</span>
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <el-dropdown v-if="code == 2">
                    <span class="el-dropdown-link">
                        销售员<i class="el-icon-arrow-down el-icon--right"></i>
                    </span>

                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>个人信息</el-dropdown-item>
                        <el-dropdown-item>切换账号</el-dropdown-item>
                        <el-dropdown-item>
                            <span @click="outSales">退出</span>
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <div id="headimg">
                    <img
                        class="headimg"
                        src="../../assets/管.jpg"
                        alt=""
                        v-if="code == 1"
                    />
                    <img
                        class="headimg"
                        src="../../assets/销.jpg"
                        alt=""
                        v-if="code == 2"
                    />
                </div>
                <h5 class="h3">Hi !{{ name }}</h5>
                <el-menu
                    default-active="2"
                    class="el-menu-vertical-demo"
                    background-color="#222d32"
                    text-color="#fff"
                    active-text-color="#ffd04b"
                    :router="true"
                >
                    <template v-if="code == 1">
                        <el-submenu
                            v-for="item in data"
                            :key="item.index"
                            :index="item.index"
                        >
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{ item.title }}</span>
                            </template>
                            <el-menu-item-group
                                v-for="val in item.subMenu"
                                :key="val.index"
                            >
                                <el-menu-item :index="val.path">{{
                                    val.title
                                }}</el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                    </template>
                    <template v-if="code == 2">
                        <el-submenu
                            v-for="item in menuData"
                            :key="item.index"
                            :index="item.index"
                        >
                            <template slot="title">
                                <i class="el-icon-location"></i>
                                <span>{{ item.title }}</span>
                            </template>
                            <el-menu-item-group
                                v-for="val in item.subMenu"
                                :key="val.index"
                            >
                                <el-menu-item :index="val.path">{{
                                    val.title
                                }}</el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                    </template>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data() {
        return {
            name: localStorage.getItem("names"),
            // 以下数据为动态渲染侧边栏目录，可增删
            code: localStorage.getItem("code"),
            // 管理员
            data: [
                {
                    index: "2",
                    title: "销售员管理",
                    subMenu: [
                        {
                            index: "2-1",
                            title: "查看销售员列表",
                            path: "/system/salesList",
                        },
                        {
                            index: "2-2",
                            title: "新增销售员",
                            path: "/system/salesAdd",
                        },
                    ],
                },
                {
                    index: "3",
                    title: "保险分类管理",
                    subMenu: [
                        {
                            index: "3-1",
                            title: "查看所有保险分类",
                            path: "/system/classifysList",
                        },
                        {
                            index: "3-2",
                            title: "新增保险分类",
                            path: "/system/classifysAdd",
                        },
                    ],
                },
                {
                    index: "4",
                    title: "保险产品管理",
                    subMenu: [
                        {
                            index: "4-1",
                            title: "查看所有保险产品",
                            path: "/system/productsList",
                        },
                        {
                            index: "4-2",
                            title: "新增保险产品",
                            path: "/system/addProducts",
                        },
                    ],
                },
                {
                    index: "5",
                    title: "保险订单管理",
                    subMenu: [
                        {
                            index: "5-1",
                            title: "查看所有订单信息",
                            path: "/system/ordersList",
                        },
                    ],
                },
                {
                    index: "6",
                    title: "客户管理",
                    subMenu: [
                        {
                            index: "6-1",
                            title: "查看所有客户信息",
                            path: "/system/adminCustomersList",
                        },
                    ],
                },
                {
                    index: "7",
                    title: "理赔管理",
                    subMenu: [
                        {
                            index: "7-1",
                            title: "查看所有理赔申请",
                            path: "/system/anminClaimsList",
                        },
                    ],
                },
                {
                    index: "8",
                    title: "管理管理员",
                    subMenu: [
                        {
                            index: "8-1",
                            title: "管理员列表",
                            path: "/system/admins",
                        },
                    ],
                },
            ],
            //销售员
            menuData: [
                {
                    index: "1",
                    title: "保险订单管理",
                    subMenu: [
                        {
                            index: "1-1",
                            title: "查款负责所有订单",
                            path: "/system/myAllOrdersList",
                        },
                    ],
                },
                {
                    index: "2",
                    title: "客户管理",
                    subMenu: [
                        {
                            index: "2-1",
                            title: "查看负责所有客户",
                            path: "/system/customersList",
                        },
                        {
                            index: "2-2",
                            title: "新增客户",
                            path: "/system/addCustomers",
                        },
                    ],
                },
                {
                    index: "3",
                    title: "理赔管理",
                    subMenu: [
                        {
                            index: "3-1",
                            title: "查看所有理赔信息",
                            path: "/system/claimsList",
                        },
                        {
                            index: "3-2",
                            title: "提交理赔凭证新增理赔",
                            path: "/system/addClaims",
                        },
                    ],
                },
                {
                    index: "4",
                    title: "我的邀请",
                    subMenu: [
                        {
                            index: "4-1",
                            title: " 发送专属链接",
                            path: "",
                        },
                    ],
                },
                {
                    index: "5",
                    title: "个人中心",
                    subMenu: [
                        {
                            index: "5-1",
                            title: "修改个人信息",
                            path: "/system/salesChangeInformation",
                        },
                        {
                            index: "5-2",
                            title: "修改密码",
                            path: "/system/salesChangePassword",
                        },
                    ],
                },
            ],
        };
    },
    methods: {
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        //管理员退出登录
        outAdmin() {
            localStorage.removeItem("code");
            this.$router.push("/");
        },
        outSales() {
            localStorage.removeItem("code");
            this.$router.push("/");
        },
    },
};
</script>

<style scoped>
.el-dropdown-link {
    cursor: pointer;
    color: #409eff;
}
.el-icon-arrow-down {
    font-size: 12px;
}
.el-submenu__title {
    width: 200px !important;
}
.h3 {
    line-height: 50px;
    color: white;
}
.headimg {
    width: 80px;
    height: 80px;
    border-radius: 50%;
}
#headimg {
    border-radius: 50%;
    width: 80px;
    height: 80px;

    margin: 0px auto;
    text-align: center;
}
.el-submenu .el-menu-item {
    min-width: 0px !important;
}
.el-aside {
    height: 90.5vh;
    text-align: center;
    background-color: #222d32 !important;
}
h4 {
    color: white;
}
#header-right {
    height: 50px;
    width: 100px;
    margin-top: 3px;
}

.el-header,
.el-footer {
    background-color: #222d32;
    color: #333;
    text-align: center;
    line-height: 60px;
    display: flex;
    justify-content: space-between;
}

.el-aside {
    background-color: #d3dce6;
    color: #333;
    /* text-align: center; */
    padding: 0;
    margin: 0;
    /* line-height: 200px; */
}

.el-main {
    background-color: #e9eef3;
    color: #333;
    /* text-align: center;
    line-height: 160px; */
}

body > .el-container {
    margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
    line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
    line-height: 320px;
}
.el-menu {
    border-right: none;
}
.el-dropdown-link {
    color: white;
}
</style>